package com.deluxelx.soul.inn.web.index;

import cn.hutool.core.collection.CollectionUtil;
import com.deluxelx.soul.inn.bean.article.ArticleVO;
import com.deluxelx.soul.inn.bean.counselor.CounselorVO;
import com.deluxelx.soul.inn.bean.course.CourseVO;
import com.deluxelx.soul.inn.bean.nav.NavBar;
import com.deluxelx.soul.inn.bean.question.QuestionVO;
import com.deluxelx.soul.inn.common.result.SoulInnResult;
import com.deluxelx.soul.inn.service.article.ArticleService;
import com.deluxelx.soul.inn.service.counselor.CounselorService;
import com.deluxelx.soul.inn.service.course.CourseService;
import com.deluxelx.soul.inn.service.nav.NavService;
import com.deluxelx.soul.inn.service.question.QuestionService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 首页
 *
 * @author: zihao.liao
 * @date: 2023/12/5 15:00
 */
@RestController
@RequestMapping("/soul/inn/index")
public class IndexController {

    @Resource
    private CourseService courseService;

    @Resource
    private NavService navService;

    @Resource
    private QuestionService questionService;

    @Resource
    private CounselorService counselorService;

    @Resource
    private ArticleService articleService;

    @GetMapping("/courseList")
    public SoulInnResult<List<CourseVO>> fetchIndexCourseList() {
        List<CourseVO> courseVOList = courseService.fetchIndexCourseList();
        if (CollectionUtil.isNotEmpty(courseVOList)) {
            return SoulInnResult.success(courseVOList);
        }
        return SoulInnResult.fail("获取首页轮播图课程列表失败");
    }

    @GetMapping("/navList")
    public SoulInnResult<List<NavBar>> fetchIndexNavList() {
        List<NavBar> navBarList = navService.fetchNavBarList();
        if (CollectionUtil.isNotEmpty(navBarList)) {
            return SoulInnResult.success(navBarList);
        }
        return SoulInnResult.fail("获取首页导航栏列表失败");
    }

    @GetMapping("/questionList")
    public SoulInnResult<List<QuestionVO>> fetchIndexQuestionList() {
        List<QuestionVO> questionVOList = questionService.fetchIndexQuestionList();
        if (CollectionUtil.isNotEmpty(questionVOList)) {
            return SoulInnResult.success(questionVOList);
        }
        return SoulInnResult.fail("获取首页问答列表失败");
    }

    @GetMapping("/counselorList")
    public SoulInnResult<List<CounselorVO>> fetchIndexCounselorList() {
        List<CounselorVO> counselorIndexList = counselorService.fetchIndexCounselorList();
        if (CollectionUtil.isNotEmpty(counselorIndexList)) {
            return SoulInnResult.success(counselorIndexList);
        }
        return SoulInnResult.fail("获取首页咨询师列表失败");
    }

    @GetMapping("/articleList")
    public SoulInnResult<List<ArticleVO>> fetchIndexArticleList() {
        List<ArticleVO> articleVOList = articleService.fetchIndexArticleList();
        if (CollectionUtil.isNotEmpty(articleVOList)) {
            return SoulInnResult.success(articleVOList);
        }
        return SoulInnResult.fail("获取首页文章列表失败");
    }
}
